#include "func.h"

void B()
{
  cout<<"Programming B:"<<endl;
  for(int i=1;i<=4;i++)
    {
      int n=2*i;
      vector<double> _x(n+1);
      vector<double> _f(n+1);
      for(int j=0;j<=n;j++)
	{
	  _x[j]=-5.0+10.0*j/n;
	  _f[j]=1.0/(1+_x[j]*_x[j]);
	}
      InterConditions Q(n+1,_x,_f);
      NewtonInterp P(Q);
      P.Interpolation_Method1();
      Polynomial p=P.get_interPoly_();
      cout<<"n = "<<n<<" the interpolation polynomial of f is: "<<endl;
      cout<<p<<endl;
      cout<<endl;
    }
}

void C()
{
  cout<<"**********************"<<endl;
  cout<<"Programming C: "<<endl;
  for(int i=1;i<=4;i++)
    {
      int n=5*i;
      vector<double> _x(n);
      vector<double> _f(n);
      for(int j=0;j<n;j++)
	{
	  _x[j]=cos((2*j+1)*M_PI/(2*n));
	  _f[j]=1.0/(1+25*_x[j]*_x[j]);
	}
      InterConditions Q(n,_x,_f);
      NewtonInterp P(Q);
      P.Interpolation_Method1();
      Polynomial p=P.get_interPoly_();
      cout<<"n = "<<n<<" the interpolation polynomial of f is: "<<endl;
      cout<<p<<endl;
      cout<<endl;
    }
}

void D()
{
  int n=5;
  vector<double> _t={0,3,5,8,13};
  vector<double> _y={0,225,383,623,993};
  vector<double> _m={1,1,1,1,1};
  vector<vector<double> > _v(n,vector<double>(1));
  _v[0][0]=75; _v[1][0]=77; _v[2][0]=80; _v[3][0]=74; _v[4][0]=72;
  InterConditions Q(n,_t,_y,_m,_v);
  NewtonInterp P(Q);
  P.Interpolation_Method1();
  Polynomial p0=P.get_interPoly_();
  cout<<"**********************"<<endl;
  cout<<"Programming D: "<<endl;
  cout<<"(a):"<<endl;
  cout<<"The interpolation polynomial:"<<endl;
  cout<<p0<<endl;
  cout<<endl;
  cout<<"the position at t=10s is: "<<p0.get_value(10)<<endl;
  cout<<"its speed at t=10s is: "<<p0.get_deri_value(10)<<endl;
  cout<<endl;
  cout<<"(b):"<<endl;
  cout<<"the derivative of this Hermite polynomial:"<<endl;
  cout<<p0.get_deri()<<endl;
  cout<<"the value of deritative at t=6 is: "<<p0.get_deri_value(6)<<endl;
  cout<<"So its maximun is bigger than 81, the car ever exceeded the speed limit! "<<endl;
}

void E()
{
  int n=7;
  vector<double> _t={0,6,10,13,17,20,28};
  vector<double> _y1={6.67,17.3,42.7,37.3,30.1,29.3,28.7};
  vector<double> _y2={6.67,16.1,18.9,15.0,10.6,9.44,8.89};
  InterConditions Q1(n,_t,_y1);
  InterConditions Q2(n,_t,_y2);
  NewtonInterp P1(Q1);
  NewtonInterp P2(Q2);
  P1.Interpolation_Method1();
  P2.Interpolation_Method1();
  Polynomial p1=P1.get_interPoly_();
  Polynomial p2=P2.get_interPoly_();
  cout<<"\n"<<endl;
  cout<<"***********************"<<endl;
  cout<<"Programming E: "<<endl;
  cout<<"(a):"<<endl;
  cout<<"the interpolation polynomial of Sample One:"<<endl;
  cout<<p1<<endl;
  cout<<endl;
  cout<<"the interpolation polynomial of Sample Two:"<<endl;
  cout<<p2<<endl;
  cout<<endl;
  cout<<"(b):"<<endl;
  cout<<"For Sample One: the value of its curve at t=43 is: "<<p1.get_value(43)<<endl;
  cout<<"For Sample Two: the value of its curve at t=43 is: "<<p2.get_value(43)<<endl;
  cout<<"it is obviously unreasonable;investigate its monotonicity,easy to find that its prediction is not feasible! we can't predict this by interpolation polynomial; in fact,it is more possible that prediction near the interpolation points is more likely to be reasonable."<<endl;
  
}
